package io.github.lee.jel.global.di.database

import android.content.Context
import androidx.room.Room
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import io.github.lee.jel.dao.JellyfinSessionDao

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
    @Provides
    fun provideDatabase(@ApplicationContext context: Context): JellyfinDatabase =
        Room.databaseBuilder(
            context, JellyfinDatabase::class.java,
            "${context.packageName}.db"
        )
            .allowMainThreadQueries()
            .build()

    @Provides
    fun provideJellyfinServerDao(database: JellyfinDatabase): JellyfinSessionDao =
        database.jellyfinServerDao()

}